package com.ruoyi.warning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.warning.domain.entity.Service;
import com.ruoyi.warning.domain.query.ServiceQuery;
import com.ruoyi.warning.mapper.ServicesMapper;
import com.ruoyi.warning.service.IServicesService;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenhc
 * @since 2025-03-26
 */
@org.springframework.stereotype.Service
public class ServicesServiceImpl extends ServiceImpl<ServicesMapper, Service> implements IServicesService {

    @Override
    public Object getAllServices(ServiceQuery query) {
        Page<Service> page = PageHelper.startPage(query.getPageNum(),query.getPageSize());
        LambdaQueryWrapper<Service> wrapper = new QueryWrapper<Service>().lambda()
                .eq(query.getDeviceId()!= null,Service::getDeviceId,query.getDeviceId())
                .eq(query.getDisable()!=null,Service::getServiceDisabled,query.getDisable())
                .like(query.getName()!=null,Service::getServiceName,query.getName());
        if(ObjectUtils.isNotEmpty(query.getStatus())){
            if(query.getStatus()==0){
                wrapper.eq(Service::getServiceStatus,0);
            }else {
                wrapper.ne(Service::getServiceStatus,0);
            }
        }
        List<Service> list = this.list(wrapper);
        TableDataInfo tableDataInfo = new TableDataInfo(list, page.getTotal());
        return tableDataInfo;
    }

    @Override
    public Object getServiceDetail(String id) {
        return this.getById(id);
    }
}
